// Copyright (c) 2022, hzmes and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.query_reports["SRM Sample Request Tongji"] = {
	"filters": [
		{
			"fieldname": "creation_from",
			"fieldtype": "Date",
			"label": "制单日期从",
			"default": frappe.datetime.year_start(),
			"width": 0
		},
		{
			"fieldname": "creation_to",
			"fieldtype": "Date",
			"label": "制单日期到",
			"default": frappe.datetime.year_end(),
			"width": 0
		},
	],

	onload: function(report) {
		report.page.add_inner_button(__("Test"), function() {
			//var filters = report.get_filter_values();			
			let data = report.data;		
			let count_filter;	
			const rows = report.datatable.datamanager._filteredRows;			
			if (rows) {
				data = data.filter((d,i) => i in rows);
				count_filter = data.filter((d,i) => i in rows).length;
			};
			const names = data.map(d => d.name);
			console.log(count_filter);
			
		});

	},

	"formatter": function(value, row, column, data, default_formatter) {

		value = default_formatter(value, row, column, data);
		let format_fields = ["workflow_state"];

		if (format_fields && data && data["workflow_state"]) {
			var color_field = data["workflow_state"];
			let color = undefined;

			if (color_field == '完成') {
				color = 'green';
			}
			if (color_field == '拒绝') {
				color = 'red';
			}
			if (color_field == '保存') {
				color = 'blue';
			}
			if (color_field == '提交') {
				color = 'orange';
			}
			if (color){
				value =`<div style='margin:0px;padding-left:5px;color:${color}!important;'>${value}</div>`            
			}	
		}

		// value =`<div style='margin:0px;padding-left:5px;color:green!important;'>${value}</div>`

		return value;
	},

	after_datatable_render: function(datatable_obj) {
		$(datatable_obj.wrapper).find(".dt-row-0").find('input[type=checkbox]').click();
	},

	get_datatable_options(options) {
        return Object.assign(options, {
            checkboxColumn: true,
			events: {
				onCheckRow: function(data) {
					// var select_row = []
					data[18].content = 'Y'
					console.log(data[2].content)
				},

				onSwitchColumn: function(data) {
					console.log('SwitchColumn')
				},
			}
        });
    },
};
